﻿using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

[System.Serializable]
public struct PlayerData
{
    public int gold;

}


public class PlayerDataSyn : NetworkBehaviour {

//    [SyncVar]
//    public int testVal = 0;

    [SyncVar]
    public PlayerData hostData;

    [SyncVar]
    public PlayerData clientData;


	// Use this for initialization
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
        if(!isLocalPlayer)
        {
            return;
        }

//        if(Input.GetKeyDown("t"))
//        {
//            testVal++;
//        }

        if(Input.GetKeyDown("c"))
        {
            CmdCommandTest(isServer);
        }

//        if(Input.GetKeyDown("r"))
//        {
//            RpcRpcTest();
//        }

	}

    [Command]
    void CmdCommandTest(bool isServer)
    {
        Debug.Log("CmdCommandTest isServer:"+isServer);

        if(isServer)
        {

            var newData = new PlayerData();
            newData.gold = hostData.gold+1;
            hostData = newData;
        }else
        {
            var newData = new PlayerData();
            newData.gold = clientData.gold+1;

            clientData = newData;
        }

    }

//    [ClientRpc]
//    void RpcRpcTest()
//    {
//        Debug.Log("RpcTest");
//    }
}
